package kp.rpc.server.vert;

import io.vertx.core.Vertx;
import kp.rpc.server.HttpServer;
import kp.rpc.server.handler.HttpServerHandler;

/**
 * vert.x 服务容器启动
 */
public class VertxHttpServer implements HttpServer {
    @Override
    public void doStart(int port) {
        // 创建vertx实例
        Vertx vertx = Vertx.vertx();
        // 创建 HTTP 服务器
        io.vertx.core.http.HttpServer httpServer = vertx.createHttpServer();
        //监听端口并处理请求
        httpServer.requestHandler(new HttpServerHandler());
        // 启动 HTTP 服务器并监听指定端口
        httpServer.listen(port, result -> {
            if (result.succeeded()) {
                System.out.println("Server is now listening on port " + port);
            } else {
                System.err.println("Failed to start server: " + result.cause());
            }
        });
    }
}
